package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Construction;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/1/16
 */

public class UserConstructionAdapter extends RecyclerAdapter<Construction, UserConstructionAdapter.ConstructionViewHolder> {

    public UserConstructionAdapter(Context context, List<Construction> dataList) {
        super(context, dataList);
    }

    @Override
    public ConstructionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_user_construction, null);
        return new ConstructionViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ConstructionViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class ConstructionViewHolder extends RecyclerAdapter.BaseViewHolder<Construction>{
        @BindView(R.id.construction_name)
        HXTextView constructionName;

        public ConstructionViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(final int position) {
            final Construction construction = dataList.get(position);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            itemView.setLayoutParams(params);
            constructionName.setText(construction.getConstructionName());
            if(construction.isChecked()){
                constructionName.setEnabled(false);
            }else {
                constructionName.setEnabled(true);
            }
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(itemView, construction, position);
                }
            });
        }
    }
}
